package com.acwer.oa.web;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.acwer.dao.sys.SysUserDao;
import com.acwer.domain.sys.SysUser;

public class SecurityUser implements UserDetails{

	private SysUser sysUser;
	public SecurityUser(SysUser sysUser) {
		this.sysUser=sysUser;
	}
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		Collection<GrantedAuthority> authorities = new ArrayList<>();
		for (String role : sysUser.getRoles()) {
			SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role);
			authorities.add(authority);
		}
		

		return authorities;
	}

	@Override
	public String getPassword() {
		return "";//sysUser.getPassword();
	}

	@Override
	public String getUsername() {
		// TODO Auto-generated method stub
		return sysUser.getAccountId();
	}

	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}

}
